package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.client.*;
import com.acme.bankapp.exception.bank.*;
import com.acme.bankapp.service.bank.network.BankServer;

import java.io.*;

public class BankApplication {

    public static ClientRegistrationListener listeners[] = new ClientRegistrationListener[3];

    public static Bank bank = new Bank(listeners);


    public static void main(String[] args) throws BankException, IOException {

        String
                path = "";

        if (args.length >= 2) {
            switch (args[0]) {
                case "-loadbank":
                    path = args[1];

                    listeners[0] = new Bank.PrintClientListener();
                    listeners[1] = new Bank.EmailNotificationListener();
                    listeners[2] = new Bank.DebugListener();
                    try {
                        BankService.readBank(bank, path);
                    } catch (Exception e) {
                        System.out.printf("Exception: %s\n", e.getMessage());
                    }

                    if (args.length == 3) {
                        switch (args[2]) {
                            case "-server":
                                BankServer server = new BankServer();
                                server.startServer();
                                break;
                        }
                    }
                    break;
                default:
                    System.out.printf("Invalid arguments\n");
            }
        }


    }

}